<?php
require_once('../../includes/user.php');
	$user=new User();
	if(isset($_POST['atc']))
	{
		if($_POST['category']==3)
		{
			$res=$user->query("select * from point_limit where type='31' ORDER BY higher desc");//since 31 for attendance
		}
		elseif($_POST['category']==1)
		{
			$res=$user->query("select * from point_limit where type='11'");
		}
?>
<link href="../../css/default.css" rel="stylesheet" type="text/css" />

	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="34%" align="center" valign="middle" class="head">Description</td>
    <td width="15%" align="center" valign="middle" class="head">From (%)</td>
    <td width="19%" align="center" valign="middle" class="head">To (%)</td>
    <td width="10%" align="center" valign="middle" class="head">Points</td>
    <td width="22%" align="center" valign="middle" class="head">Action</td>
  </tr>
  <?php
  	while($row=mysql_fetch_array($res))
	{
   ?>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="middle"><span id="descr<?php echo $row['id']; ?>"><?php echo $row['desc']; ?></span></td>
    <td align="center" valign="middle"><span id="low<?php echo $row['id']; ?>"><?php echo $row['lower']; ?></span></td>
  	<td align="center" valign="middle"><span id="hi<?php echo $row['id']; ?>"><?php echo $row['higher']; ?></span></td>
    <td align="center" valign="middle"><span id="p<?php echo $row['id']; ?>"><?php echo $row['pts']; ?></span></td>
    <td align="center" valign="middle"><span id="action<?php echo $row['id']; ?>"><span class="smartlink" onclick="changelimit(<?php echo $row['id']; ?>)">Change</span></span></td>
  </tr>
  <?php
  } 
  ?>
</table>
<script>
	function changelimit(id)
	{
$('#descr'+id).html('<input type="textfield" id="desci'+id+'" value="'+$('#descr'+id).html()+'" style=" width: 100px" />');	
$('#low'+id).html('<input type="textfield" id="lowi'+id+'" value="'+$('#low'+id).html()+'" style=" width: 50px" />');
$('#hi'+id).html('<input type="textfield" id="hii'+id+'" value="'+$('#hi'+id).html()+'" style=" width: 50px" />');
$('#p'+id).html('<input type="textfield" id="pi'+id+'" value="'+$('#p'+id).html()+'" style=" width: 50px" />');
$('#action'+id).html('<span onclick="updatepoints('+id+')" class="smartlink">update</span>');
	}
	function updatepoints(id)
	{
		$.post('settings/pt_system/update_change.php',{desc:$('#desci'+id).val(),higher:$('#hii'+id).val(),lower:$('#lowi'+id).val(),pts:$('#pi'+id).val(),pid:id},function(){
		$('#descr'+id).html($('#desci'+id).val());
		$('#low'+id).html($('#lowi'+id).val());
		$('#hi'+id).html($('#hii'+id).val());
		$('#p'+id).html($('#pi'+id).val());
			$('#notice').html('Points settings saved Successfully').show().fadeOut(3000);
		});
		$('#action'+id).html('<span onclick="changelimit('+id+')" class="smartlink">change</span>');
	}
</script>
<?php
	}
	if(isset($_POST['extra']))
	{
?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="3"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

      <tr>
        <td height="22">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="44%" align="right" valign="middle" class="head">Select Mode :</td>
                <td width="1%">&nbsp;</td>
                <td width="27%"><select name="mode" class="FormTextFeild" id="mode">
                	<option value="0">- - - Select - - -</option>
                    <option value="1">Intra</option>
                    <option value="2">Inter</option>
                  </select>                </td>
                <td width="28%"><span id="sbpt_loading" style="display:none;"><img src="img/status/loading.gif" /></span></td>
              </tr>
            </table>        </td>
      </tr>
    </table></td>
    </tr>
  <tr>
    <td colspan="3" align="center" valign="middle"><div id="subload"></div></td>
    </tr>
</table>
<script>
	$('#mode').change(function(){
	$('#sbpt_loading').show();
	$.post("settings/pt_system/givedetails.php",{mode:$('#mode').val()},function(data){
	$('#subload').html(data);
	$('#sbpt_loading').hide();
	});});
</script>
<?php
	}
	if(isset($_POST['mode'])&&$_POST['mode']!=0)
	{
		$extra_res=$user->query("select * from point_limit where type='2$_POST[mode]' ORDER BY lower asc");
?>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle" class="head">&nbsp;</td>
    <td align="center" valign="middle" class="head">&nbsp;</td>
    <td align="center" valign="middle" class="head">&nbsp;</td>
    <td align="center" valign="middle" class="head">&nbsp;</td>
  </tr>
  <tr>
    <td align="right" valign="middle" class="head">Prize Level</td>
    <td align="center" valign="middle" class="head">&nbsp;</td>
    <td align="left" valign="middle" class="head">Points</td>
    <td align="left" valign="middle" class="head">Action</td>
  </tr>
  <?php while($extra_row=mysql_fetch_array($extra_res)){ ?>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="right" valign="middle"><?php echo $extra_row['desc']; ?></td>
    <td align="center" valign="middle">&nbsp;</td>
    <td align="left" valign="middle"><span id="p<?php echo $extra_row['id']; ?>"><?php echo $extra_row['pts']; ?></span></td>
    <td align="left" valign="middle"><span id="action<?php echo $extra_row['id']; ?>"><span class="smartlink" onclick="changelimit(<?php echo $extra_row['id']; ?>)">Change</span></span></td>
  </tr>
  <tr>
    <td width="37%" align="center" valign="middle">&nbsp;</td>
    <td width="11%" align="center" valign="middle">&nbsp;</td>
    <td width="14%" align="center" valign="middle">&nbsp;</td>
    <td width="38%" align="center" valign="middle">&nbsp;</td>
    </tr>
    <?php } ?>
</table>
<script>
	function changelimit(id)
	{	
$('#p'+id).html('<input type="textfield" id="pi'+id+'" value="'+$('#p'+id).html()+'" style=" width: 50px" />');
$('#action'+id).html('<span onclick="updatepoints('+id+')" class="smartlink">update</span>');
	}
	function updatepoints(id)
	{
		$.post('settings/pt_system/update_change.php',{pts:$('#pi'+id).val(),pid:id},function(){
		$('#p'+id).html($('#pi'+id).val());
			$('#notice').html('Points settings saved Successfully').show().fadeOut(3000);
		});
		$('#action'+id).html('<span onclick="changelimit('+id+')" class="smartlink">change</span>');
	}
</script>
<?php
	}
?>
